package com.example.IO;

import java.io.*;

public class Test3IO {
    public static void main(String[] args) throws IOException {
        //method1();
        //method2();

        //就要利用缓冲流去拷贝文件

        //创建一个字节缓冲输入流
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream("D:\\剪辑素材\\新建文件夹\\0.背景.jpg"));
        //创建一个字节缓冲输出流
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("aaa.jpg"));

        int b;
        while ((b = bis.read()) != -1) {
            bos.write(b);
        }

        bis.close();
        bos.close();

    }

    private static void method2() throws IOException {
        FileInputStream fis = new FileInputStream("D:\\剪辑素材\\新建文件夹\\0.背景.jpg");
        FileOutputStream fos = new FileOutputStream("ddd.jpg");

        byte[] bytes = new byte[1024];
        int len;    //本次读到的有效字节个数---这次读了几个字节
        while ((len = fis.read(bytes)) != -1) {
            fos.write(bytes, 0, len);
        }

        fis.close();
        fos.close();
    }

    private static void method1() throws IOException {
        //创建了字节输入流,准备读数据
        FileInputStream fis = new FileInputStream("D:\\剪辑素材\\新建文件夹\\0.背景.jpg");
        //创建了字节输出流,准备写数据
        FileOutputStream fos = new FileOutputStream("ddd.jpg");

        int b;
        while ((b = fis.read()) != -1) {
            fos.write(b);
        }

        fis.close();
        fos.close();
    }
}
